<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '400px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        legend: {},
        tooltip: {},
        dataset: {
          dimensions: ['product', '2015', '2016', '2017'],
          source: [
            { product: '1月', 2015: 43.3, 2016: 85.8, 2017: 93.7 },
            { product: '2月', 2015: 83.1, 2016: 73.4, 2017: 55.1 },
            { product: '3月', 2015: 86.4, 2016: 65.2, 2017: 82.5 },
            { product: '4月', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
            { product: '5月', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
            { product: '6月', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
            { product: '7月', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
            { product: '8月', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
            { product: '9月', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
            { product: '10月', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
            { product: '11月', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
            { product: '12月', 2015: 72.4, 2016: 53.9, 2017: 39.1 },
          ]
        },
        xAxis: { type: 'category' },
        yAxis: {},
        // Declare several bar series, each will be mapped
        // to a column of dataset.source by default.
        series: [
          {
            type: 'bar',// 此系列自己的调色盘。
            color: '#E062AE'
          },
          {
            type: 'bar',// 此系列自己的调色盘。
            color: '#32C5E9'
          },
          {
            type: 'bar',// 此系列自己的调色盘。
            color: '#67E0E3'
          },

        ]
      })
    }
  }
}
</script>
